#include <aphw/StatusCodes.hpp>

#include <boost/python.hpp>
#include <ham/hamsterdb.h>

using namespace boost::python;

namespace
{

enum StatusCodes
{
    SUCCESS = HAM_SUCCESS,
    INV_KEYSIZE = HAM_INV_KEYSIZE,
    INV_PAGESIZE = HAM_INV_PAGESIZE,
    OUT_OF_MEMORY = HAM_OUT_OF_MEMORY,
    NOT_INITIALIZED = HAM_NOT_INITIALIZED,
    INV_PARAMETER = HAM_INV_PARAMETER,
    INV_FILE_HEADER = HAM_INV_FILE_HEADER,
    INV_FILE_VERSION = HAM_INV_FILE_VERSION,
    KEY_NOT_FOUND = HAM_KEY_NOT_FOUND,
    DUPLICATE_KEY = HAM_DUPLICATE_KEY,
    INTEGRITY_VIOLATED = HAM_INTEGRITY_VIOLATED,
    INTERNAL_ERROR = HAM_INTERNAL_ERROR,
    DB_READ_ONLY = HAM_DB_READ_ONLY,
    BLOB_NOT_FOUND = HAM_BLOB_NOT_FOUND,
    PREFIX_REQUEST_FULLKEY = HAM_PREFIX_REQUEST_FULLKEY,
    IO_ERROR = HAM_IO_ERROR,
    CACHE_FULL = HAM_CACHE_FULL,
    NOT_IMPLEMENTED = HAM_NOT_IMPLEMENTED,
    FILE_NOT_FOUND = HAM_FILE_NOT_FOUND,
    WOULD_BLOCK = HAM_WOULD_BLOCK,
    NOT_READY = HAM_NOT_READY,
    LIMITS_REACHED = HAM_LIMITS_REACHED,
    ACCESS_DENIED = HAM_ACCESS_DENIED,
    ALREADY_INITIALIZED = HAM_ALREADY_INITIALIZED,
    NEED_RECOVERY = HAM_NEED_RECOVERY,
    CURSOR_STILL_OPEN = HAM_CURSOR_STILL_OPEN,
    FILTER_NOT_FOUND = HAM_FILTER_NOT_FOUND,
    CURSOR_IS_NIL = HAM_CURSOR_IS_NIL,
    DATABASE_NOT_FOUND = HAM_DATABASE_NOT_FOUND,
    DATABASE_ALREADY_EXISTS = HAM_DATABASE_ALREADY_EXISTS,
    DATABASE_ALREADY_OPEN = HAM_DATABASE_ALREADY_OPEN,
    LOG_INV_FILE_HEADER = HAM_LOG_INV_FILE_HEADER
    // EMPTY_DATABASE_NAME = HAM_EMPTY_DATABASE_NAME,
    // FIRST_DATABASE_NAME = HAM_FIRST_DATABASE_NAME,
    //DUMMY_DATABASE_NAME = HAM_DUMMY_DATABASE_NAME,
};

std::string strError(StatusCodes c) {
    return ham_strerror(c);
}

}

namespace aphw
{

void init_StatusCodes()
{
    
    enum_< ::StatusCodes >("StatusCodes")
        .value("SUCCESS", ::SUCCESS)
        .value("INV_KEYSIZE", INV_KEYSIZE)
        .value("INV_PAGESIZE", INV_PAGESIZE)
        .value("OUT_OF_MEMORY", OUT_OF_MEMORY)
        .value("NOT_INITIALIZED", NOT_INITIALIZED)
        .value("INV_PARAMETER", INV_PARAMETER)
        .value("INV_FILE_HEADER", INV_FILE_HEADER)
        .value("INV_FILE_VERSION", INV_FILE_VERSION)
        .value("KEY_NOT_FOUND", KEY_NOT_FOUND)
        .value("DUPLICATE_KEY", DUPLICATE_KEY)
        .value("INTEGRITY_VIOLATED", INTEGRITY_VIOLATED)
        .value("INTERNAL_ERROR", INTERNAL_ERROR)
        .value("DB_READ_ONLY", DB_READ_ONLY)
        .value("BLOB_NOT_FOUND", BLOB_NOT_FOUND)
        .value("PREFIX_REQUEST_FULLKEY", PREFIX_REQUEST_FULLKEY)
        .value("IO_ERROR", IO_ERROR)
        .value("CACHE_FULL", CACHE_FULL)
        .value("NOT_IMPLEMENTED", NOT_IMPLEMENTED)
        .value("FILE_NOT_FOUND", FILE_NOT_FOUND)
        .value("WOULD_BLOCK", WOULD_BLOCK)
        .value("NOT_READY", NOT_READY)
        .value("LIMITS_REACHED", LIMITS_REACHED)
        .value("ACCESS_DENIED", ACCESS_DENIED)
        .value("ALREADY_INITIALIZED", ALREADY_INITIALIZED)
        .value("NEED_RECOVERY", NEED_RECOVERY)
        .value("CURSOR_STILL_OPEN", CURSOR_STILL_OPEN)
        .value("FILTER_NOT_FOUND", FILTER_NOT_FOUND)
        .value("CURSOR_IS_NIL", CURSOR_IS_NIL)
        .value("DATABASE_NOT_FOUND", DATABASE_NOT_FOUND)
        .value("DATABASE_ALREADY_EXISTS", DATABASE_ALREADY_EXISTS)
        .value("DATABASE_ALREADY_OPEN", DATABASE_ALREADY_OPEN)
        .value("LOG_INV_FILE_HEADER", LOG_INV_FILE_HEADER)
        ;

    def("strerror", &::strError);
}

}
